<?php

if(PARCL_EXEC !== 1) {
    die('<h1>Incorrect Access</h1>You cannot access this file directly.<br/>' .
         'If you got this error message by clicking a link on the site,' .
         'please notify the webmaster as soon as possible.');
}

/**
 * Purpose     : The news module wrapper class.
 * Description : Should contain the general execution functions for the news module.
 * - Construct -
 * No comment as of yet.
 */

class News {

    public function __construct() {

    }

    /**
     * Input       : $number: The number of news to be retreived.
     * Output      : $news: A properly formed array ready for template parsing.
     * Description : This function does everything necessary to properly generate
                     the news array and preparing the result-set returned to a
                     template parsable array.
     * Errors      : None.
     * Assumptions : That $number is an integer.
     * Dev Notes   : Lots of things to be done here. The "editedby" method does
                     not exist so the entire if clause makes parcl crash if it
                     evaluates true.
     */

    public function Execute($number) {
        $news = NewsQueries::GetNews((int) $number);
        $registry = Registry::GetInstance();
        foreach($news as &$newses) {
            if(!is_null($newses['edited'])) { // This thing here does not work!
                $editedby = $newses->getEditedBy($newses); // getEditedBy does not exist.
                $newses['editedbyid'] = $editedby['id'];
                $newses['editedby'] = $editedby['name'];
            }
            $newses['posted'] = date($registry->conf->shortDateFormat, $newses['posted']);
        }
        return $news;
    }
}